package cn.xiuxius.embedded.command.extension;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import picocli.CommandLine;

import java.util.concurrent.Callable;

@CommandLine.Command(name = "ex",
        description = "Extension command",
        mixinStandardHelpOptions = true,
        subcommands = {
                    ExAdvancedFlashCommand.class,
        }
)
@Slf4j
@Getter
public class ExCommand implements Callable<Integer> {

    @CommandLine.Spec
    CommandLine.Model.CommandSpec spec;

    @Override
    public Integer call() {
        if (prepare() != 0) {
            return 1;
        }
        return 0;
    }

    public int prepare() {
        if (!spec.commandLine().getParseResult().hasSubcommand()) {
            CommandLine.usage(this, System.out);
            return 1;
        }
        return 0;
    }

}
